Expand description
Opinionated 2D math library for building GUIs.
Includes vectors, positions, rectangles etc.
Conventions (unless otherwise specified):
- All angles are in radians
- X+ is right and Y+ is down.
- (0,0) is left top.
- Dimension order is always
x y
§Integrating with other math libraries.
emath
does not strive to become a general purpose or all-powerful math library.
For that, use something else (glam
, nalgebra
, …)
and enable the mint
feature flag in emath
to enable implicit conversion to/from emath
.
§Feature flags
§Optional dependencies
Re-exports§
Modules§
- One- and two-dimensional alignment (
Align::Center
,Align2::LEFT_TOP
etc). - Easing functions for animations.
- Find “simple” numbers is some range. Used by sliders.
Structs§
- This struct tracks recent values of some time series.
- Wraps a floating-point value to add total order and hash. Possible types for
T
aref32
andf64
. - A position on screen.
- Inclusive range of floats, i.e.
min..=max
, but more ergonomic thanRangeInclusive
. - A rectangular region of space.
- Linearly transforms positions from one
Rect
to another. - Represents a rotation in the 2D plane.
- Linearly transforms positions via a translation, then a scaling.
- A vector has a direction and length. A
Vec2
is often used to represent a size. - Two bools, one for each axis (X and Y).
Traits§
- Extension trait to provide
ord()
method. - Implemented for all builtin numeric types
Functions§
- Return true when arguments are the same within some rounding error.
- Ease in, ease out.
- Calculate a lerp-factor for exponential smoothing using a time step.
- Use as few decimals as possible to show the value accurately, but within the given range.
- If you have a value animating over time, how much towards its target do you need to move it this frame?
- Where in the range is this value? Returns 0-1 if within the range.
- Linear interpolation.
- Wrap angle to
[-PI, PI]
range. pos2(x, y) == Pos2::new(x, y)
- Linearly remap a value from one range to another, so that when
x == from.start()
returnsto.start()
and whenx == from.end()
returnsto.end()
. - Like
remap
, but also clamps the value so that the returned value is always in theto
range. - Round a value to the given number of decimal places.
vec2(x, y) == Vec2::new(x, y)